let username = document.querySelector('#username');
let pwd = document.querySelector('#pwd');
let rbtn = document.querySelector('#rbtn');
let tip = document.querySelector('.tip');

rbtn.onclick = function(){
    let x = new XMLHttpRequest();
        x.open('post','/register');
        x.setRequestHeader('Content-type','application/x-www-form-urlencoded')
        x.send(`username=${username.value}&pwd=${pwd.value}`);
        x.responseType = 'json';
        x.onreadystatechange = function(){
            if(x.readyState === 4 && x.status === 200){
                if(x.response.code===200){
                    //注册成功
                    console.log(x.response);
                    tip.innerHTML = `注册成功！去<a href="/login">登录</a>`
                }else{
                    // 注册失败
                    console.log(x.response);
                    tip.innerHTML = x.response.msg;
                }
            }
        }
}